/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.samples.util;

import java.util.logging.Level;

import de.teamskill.pux.engine.Logging;
import de.teamskill.pux.engine.Network;
import de.teamskill.pux.engine.AbstractNode;
import de.teamskill.pux.library.math.AdditionNode;
import de.teamskill.pux.library.math.RandomNumberNode;
import de.teamskill.pux.library.util.PrintNode;

/**
 * RandomNumberAddTest This sample creates a network of two input nodes
 * (generating one random number each), an Add node summing up the values from
 * the input nodes, and a simple output node printing the result.
 * 
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 * 
 */
public class RandomNumberAddTest implements Logging {

	/**
	 * net
	 */
	private Network net;

	/**
	 * RandomNumberAddTest Constructor
	 * 
	 */
	public RandomNumberAddTest() {
		LOG_NET.setLevel(Level.ALL);
		LOG_NODE.setLevel(Level.ALL);
		LOG_PORT.setLevel(Level.ALL);

		setup();
		start();
	}

	/**
	 * setup
	 * 
	 */
	private void setup() {
		net = new Network();

		AbstractNode rand1 = new RandomNumberNode();
		AbstractNode rand2 = new RandomNumberNode();
		AbstractNode add = new AdditionNode("ADD", 2, false);
		AbstractNode print = new PrintNode();

		rand1.setStartupNode(true);
		rand2.setStartupNode(true);

		net.addNode(rand1);
		net.addNode(rand2);
		net.addNode(add);
		net.addNode(print);

		net.connect(rand1.getOutputPort("OUT1"), add.getInputPort("IN1"));
		net.connect(rand2.getOutputPort("OUT1"), add.getInputPort("IN2"));
		net.connect(add.getOutputPort("OUT"), print.getInputPort("IN1"));
	}

	/**
	 * start
	 * 
	 */
	private void start() {
		net.start();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new RandomNumberAddTest();
	}

}
